﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utils;
using Settings;
using System.Data;
using System.Data.SqlClient;

namespace SMSROUTER.Business
{
    public partial class SysUserGroup
    {
        public static SysUserGroup GetByUserIDAndGroupID(int UserID, int GroupID)
        {
            return ObjectClass.CreateInstance<SysUserGroup>(SqlHelper.ExecuteReader(AppSetting.ConnectionString, CommandType.Text, string.Format("SELECT * FROM SysUserGroup WHERE UserID = {0} AND GroupID = {1}", UserID, GroupID)));
        }

        public static bool Delete1(int UserID, int GroupID)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, string.Format("DELETE FROM SysUserGroup WHERE UserID = {0} AND GroupID = {1}", UserID, GroupID));
                    return (result > 0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Hiện tại các hàm gen ra chưa sử dụng được do chưa có store được gen trong csdl
        /// </summary>
        /// <returns></returns>
        public bool Save1()
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(AppSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, string.Format("INSERT INTO SysUserGroup (UserID,GroupID) VALUES ({0},{1})", UserID, GroupID));
                    return (result > 0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
